/**
 * @author Nicolás Galliano
 */

/*
 * ManageBanPeriods.java
 *
 * Created on 03/02/2010, 16:05:35
 */

//    Panel
//    CDU 11 - Gestionar período de veda.
//    P11.1. Período de Veda.

package tpdisenio2009.mvp.display;

import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JComponent;
import tpdisenio2009.model.beans.TournamentDate;
import javax.swing.JOptionPane;

/**
 * @author Pablito
 */
public class ManageBanPeriodsViewImpl extends javax.swing.JPanel implements ManageBanPeriodsView{

    /** Creates new form ManageBanPeriods */
    public ManageBanPeriodsViewImpl() {
        initComponents();        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPaneTablaFechas = new javax.swing.JScrollPane();
        jTableTablaFechas = new javax.swing.JTable();
        jButtonSave = new javax.swing.JButton();

        setName("Form"); // NOI18N

        jScrollPaneTablaFechas.setName("jScrollPaneTablaFechas"); // NOI18N

        jTableTablaFechas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null},
                {"", null, null, null, null, null}
            },
            new String [] {
                "Nro. de Fecha", "Fecha Inicial", "Hora Inicial", "Fecha Final", "Hora Final", "Estado"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true, true, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableTablaFechas.setName("jTableTablaFechas"); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(ManageBanPeriodsViewImpl.class);
        jTableTablaFechas.setSelectionBackground(resourceMap.getColor("jTableTablaFechas.selectionBackground")); // NOI18N
        jTableTablaFechas.setSelectionForeground(resourceMap.getColor("jTableTablaFechas.selectionForeground")); // NOI18N
        jTableTablaFechas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPaneTablaFechas.setViewportView(jTableTablaFechas);
        jTableTablaFechas.getColumnModel().getColumn(0).setResizable(false);
        jTableTablaFechas.getColumnModel().getColumn(0).setPreferredWidth(70);
        jTableTablaFechas.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTableTablaFechas.columnModel.title0")); // NOI18N
        jTableTablaFechas.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTableTablaFechas.columnModel.title1")); // NOI18N
        jTableTablaFechas.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTableTablaFechas.columnModel.title2")); // NOI18N
        jTableTablaFechas.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTableTablaFechas.columnModel.title3")); // NOI18N
        jTableTablaFechas.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTableTablaFechas.columnModel.title4")); // NOI18N

        jButtonSave.setText(resourceMap.getString("jButtonSave.text")); // NOI18N
        jButtonSave.setName("jButtonSave"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPaneTablaFechas, javax.swing.GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE)
                    .addComponent(jButtonSave, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jScrollPaneTablaFechas, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                .addGap(11, 11, 11)
                .addComponent(jButtonSave)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonSave;
    private javax.swing.JScrollPane jScrollPaneTablaFechas;
    private javax.swing.JTable jTableTablaFechas;
    // End of variables declaration//GEN-END:variables
    
    public void cleanCell( int row, int col ) {
        ManageBanPeriodsTableModel model = ( ManageBanPeriodsTableModel) jTableTablaFechas.getModel();
        model.cleanCell( row, col );
    }

    public TournamentDate getTournamentDate( int row ) {
         ManageBanPeriodsTableModel model = ( ManageBanPeriodsTableModel) jTableTablaFechas.getModel();
         return model.getTournamentDate( row );
    }

    public TournamentDate getCurrentEditDate() {
        ManageBanPeriodsTableModel model = ( ManageBanPeriodsTableModel) jTableTablaFechas.getModel();
        return model.getCurrentEditDate();
    }

    public void loadTournamentDates( List<TournamentDate> dates ) {
        ManageBanPeriodsTableModel model = new ManageBanPeriodsTableModel( dates );
        jTableTablaFechas.setModel( model );
    }

    public void addSaveListener(ActionListener listener) {
        jButtonSave.addActionListener( listener );
    }

    public void removeSaveListener(ActionListener listener) {
        jButtonSave.removeActionListener( listener );
    }

    public void showError( int focusElement, String errorMessage, String titleMessageWindow ) {
        JOptionPane.showMessageDialog( this,
                errorMessage,
                titleMessageWindow,
                JOptionPane.ERROR_MESSAGE);        
    }
    
    public void showNotification( String notifiactionMessage, String notificationMessageTitle ) {
        JOptionPane.showMessageDialog( this,
                notifiactionMessage,
                notificationMessageTitle,
                JOptionPane.INFORMATION_MESSAGE);
    }

    public boolean showConfirmation( String notifiactionMessage ) {
        int confirm = JOptionPane.showConfirmDialog( this, notifiactionMessage, "Confirmación", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE );

        if (JOptionPane.YES_OPTION == confirm)
            return true;
        else
            return false;
    }

    public JComponent asWidget() {
        return this;
    }
}